<template>
	<view class="order-info">
		<view class="goods-section">
			<view class="order-no">订单编号：{{ orderData.orderInfo.order_no }}</view>
			<!-- 商品列表 -->
			<view class="detail-list" v-for="(item, index) in orderData.orderList" :key="index">
				<view class="g-item">
					<image :src="item.logo"></image>
					<view class="right">
						<text class="title clamp" style="font-size: 26rpx;">{{ item.goods_name }}</text>
						<text class="spec">
							<text  v-if="item.rule != 0">{{ item.rule.split('※').join(' ') }}</text>
						</text>
						<view class="price-box">
							<text class="price">￥{{ item.price }}</text>
							<text class="number">x {{ item.cart_num }}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="real-pay">
				<view class="real-price">
					实付款
					<text style="color: #e93939;margin-left: 10rpx;">￥{{ orderData.orderInfo.pay_price }}</text>
				</view>
			</view>
		</view>
		<view class="store-info">
			<view class="store-name-box">
				<view class="store-name">{{ orderData.storeInfo.name }}</view>
				<view class="store-address">{{ orderData.storeInfo.address }}</view>
				<view class="store-address">联系电话：{{ orderData.storeInfo.phone }}</view>
			</view>
		</view>
		
		<view class="sub-btn" :style="{'background': themeBg}" @click="confirm">确认核销</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				orderData: {
					orderInfo: {},
					storeInfo: {}
				},
				themeBg: ''
			}
		},
		onLoad(options) {
			this.code = options.code
			this.getOrderDetail()
		},
		onShow() {
			let theme = uni.getStorageSync('theme')
			this.themeBg = 'linear-gradient(90deg, ' + theme.bg1 + ', ' + theme.bg2 + ')'
		},
		methods: {
			// 获取订单详情
			async getOrderDetail() {
				let res = await this.$api.verification.getOrderInfo.get({code: this.code})
				if (res.code == 0) {
					this.orderData = res.data
				} else {
					this.$tool.error(res.msg)
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages/verification/index'
						})
					}, 1000)
				}
				
			},
			// 确认核销
			async confirm() {
				let res = await this.$api.verification.confirm.post({
					store_id: this.orderData.orderInfo.store_id,
					code: this.code
				})
				
				if (res.code == 0) {
					this.$tool.success(res.msg)
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages/verification/index'
						})
					}, 800)
				} else {
					this.$tool.error(res.msg)
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.order-info {
		width: 100%;
		height: 100%;
		background: #f4f4f5;
		padding-top: 20rpx;
	}
	.goods-section {
		margin-top: 16upx;
		background: #fff;
		width: calc(100% - 40rpx);
		margin: 0 auto;
		margin-top: 20rpx;
		border-radius: 20rpx;
		padding-top: 20rpx;
		.order-no {
			padding-left: 20rpx;
			font-size: 28rpx;
			padding-bottom: 20rpx;
			border-bottom: 1px solid #f4f4f5;
		}
	
		.g-header {
			display: flex;
			align-items: center;
			height: 84upx;
			padding: 0 30upx;
			position: relative;
		}
	
		.logo {
			display: block;
			width: 50upx;
			height: 50upx;
			border-radius: 100px;
		}
	
		.name {
			font-size: 30upx;
			color: $font-color-base;
			margin-left: 24upx;
		}
	
		.g-item {
			display: flex;
			margin: 20upx 30upx;
	
			image {
				flex-shrink: 0;
				display: block;
				width: 140upx;
				height: 140upx;
				border-radius: 4upx;
			}
	
			.right {
				flex: 1;
				padding-left: 24upx;
				overflow: hidden;
			}
	
			.title {
				font-size: 30upx;
				color: $font-color-dark;
			}
	
			.spec {
				color: $font-color-light;
				font-size:24rpx;
				height: 30rpx;
				display: block;
			}
	
			.price-box {
				display: flex;
				align-items: center;
				font-size: 32upx;
				color: $font-color-dark;
				padding-top: 10upx;
	
				.price {
					margin-bottom: 4upx;
					color: #e93939;
				}
				.number{
					font-size: 26upx;
					color: $font-color-base;
					margin-left: 20upx;
				}
			}
		}
	}
	.real-pay {
		width: 100%;
		height: 86rpx;
		border-top: 1px solid #f4f4f5;
		padding-bottom: 20rpx;
		padding-top: 20rpx;
	}
	.real-price {
		margin-left: 60%;
	}
	.store-info {
		width: calc(100% - 40rpx);
		height: 180rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		border-radius: 20rpx;
		background: #fff;
		padding-left: 20px;
		padding-top: 10px;
		display: flex;
		.store-name-box {
			width: 100%;
			height: 100%;
			display: flex;
			flex-direction: column;
			.store-address {
				font-size: 24rpx;
				color: #909399;
				margin-top: 20rpx;
			}
		}
		.ver-btn {
			padding-top: 20rpx;
			padding-right: 20rpx;
		}
	}
	.sub-btn {
		color: #fff;
		width: 90%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 40rpx;
		margin: 0 auto;
		margin-top: 20rpx;
	}
</style>